﻿#region using namespaces

using System.Configuration;
using System.Web.Configuration;
using RSteel.DAL;

#endregion

namespace RSteel.DAO
{
    public class BaseContext
    {
        protected static readonly string connectionString;

        static BaseContext()
        {
            ConnectionStringSettings connectionStringSettings =
                WebConfigurationManager.ConnectionStrings["rsteelConnectionString"];
            if (connectionStringSettings != null)
            {
                connectionString = WebConfigurationManager.ConnectionStrings["rsteelConnectionString"].ConnectionString;
            }
        }

        public static RSteelDbDataContext GetDataContext()
        {
            RSteelDbDataContext context;

            //Initialize the Log4Net from the XML
            //log4net.Config.XmlConfigurator.Configure();

            //Create an instance of the LINQLogger
            //LinqLogger linqLogger = new LinqLogger(LogManager.GetLogger("RSteel"));


            if (string.IsNullOrEmpty(connectionString))
            {
                context = new RSteelDbDataContext();
            }
            else
            {
                context = new RSteelDbDataContext(connectionString);
            }


            //Set the linqLogger to the log of the DataContext
            //context.Log = new DebuggerWriter();
            return context;
        }
    }
}